/*
 * Copyright 2019 成都深地领航能源科技有限公司. All rights reserved.
 * PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.sdlh.demo.stream;

import java.text.SimpleDateFormat;
import java.util.Scanner;

public class CarDemo {
    public static void main(String[] args) {
        try {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入入场时间（格式为2022-05-30 12:00）:");
            String input1 = sc.nextLine();
            String time1 = input1.split(" ")[1];
            System.out.println("请输入出场时间（格式为2022-05-31 15:30）:");
            String input2 = sc.nextLine();
            String time2 = input2.split(" ")[1];

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String enterTime = input1 + ":00";
            String exitTime = input2 + ":00";
            long start = sdf.parse(enterTime).getTime();
            long end = sdf.parse(exitTime).getTime();

            long seconds = (end - start)/1000;
            long days = seconds/3600/24;
            long hours = seconds/3600 - days*24;
            long minutes = seconds/60 - days*24*60 - hours*60;
            long sum = days*30 + hours*2 + (minutes == 0 ? 0 : 2);
            System.out.println("停车时间共"+days+"天"+hours+"小时"+minutes+"分钟,应收费"+sum+"元");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
